/*
 * @Author: 恒恒 1067531094@qq.com
 * @Date: 2022-10-12 17:09:52
 * @LastEditors: 恒恒 1067531094@qq.com
 * @LastEditTime: 2022-10-13 16:56:08
 * @FilePath: \作业\router\loginRouter.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
//登录页面路由
const express = require('express')
const router = express.Router()

const fs = require('fs')
let persons = fs.readFileSync(__dirname + "/persons.json", "utf8");
persons = JSON.parse(persons);

router.get('/login', (req, res) => {
    res.render('login.html')
})

router.post('/login', (req, res) => {
    let { tel, pass } = req.body
    // console.log(tel)
    // console.log(pass)
    let p = persons.find((item) => {
        console.log(item)
        return item.username == tel && item.password == pass
    })

    console.log(p);
    if (p) {
        res.send('登陆成功')
    }
    else {
        res.send('登录失败')
    }
})
module.exports = router